package cn.takujo.simple.elasticsearch.client;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.apache.http.HttpEntity;
import org.apache.http.ParseException;
import org.apache.http.util.EntityUtils;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.MapType;

public class HttpEntityToMap {

	public static Map<String, Object> trans(HttpEntity entity) throws ParseException, IOException {
		String json = EntityUtils.toString(entity);
		ObjectMapper om = new ObjectMapper();
		MapType mapType = om.getTypeFactory().constructMapType(HashMap.class, String.class, Object.class);
		return om.readValue(json, mapType);
	}

}
